package com.hx.io.randomaccess;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * 1.是不完全覆盖操作
 * 2.可以进行插入操作
 *
 * @author jxlgcmh
 * @create 2019-05-10 09:44
 */
public class Demo1 {
    public static void main(String[] args) {
        RandomAccessFile src = null;
        RandomAccessFile dst = null;
        try {
            src = new RandomAccessFile("a.txt", "r");
            dst = new RandomAccessFile("aa.txt", "rw");
            byte[] buf = new byte[1024];
            int len;
            while ((len = src.read(buf)) != -1) {
                dst.write(buf, 0, len);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (src != null) {
                try {
                    src.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (dst != null) {
                try {
                    dst.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }

    }
}
